<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.ParamReasonType"%>
<%@page import="com.is.control.ParamReasonTypeControl"%>
<%@page import="com.is.model.ParamReasonTypeGS"%>
<%@page import="com.is.control.ParamReasonTypeGSControl"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../resources/css/user_info.css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<style type="text/css">
	.main{width:280px; padding:20px 0; margin:0 auto;}
	.lack_one{display:block; float:left; width:60px; height:26px; line-height:26px; text-align:right;}
	.detail{float:right; width:220px;}
	.submit{text-align:center; width:100%; float:right; margin-bottom:20px;}
</style>
<title>设置缺勤计算公式</title>
</head>
<body>
<%
          String pageType = ParamUtil.getString(request,"pageType","0");
          int stuyear =ParamStuyearControl.getCurrentStuyearId();
          List<ParamReasonType> types = ParamReasonTypeControl.getAllReaons();
          if(pageType.equals("0")){
%>
<form action="">
<div class="main"><span class="lack_one">1次缺勤</span>
<div class="detail">
<%
          for(ParamReasonType type:types){
              if(type.getId()!=3&&type.getId()!=1){
        	  int oldNum = ParamReasonTypeGSControl.getNumByTypeAndStuyear(type.getId(),stuyear);
%>
=<input type="text" name="<%=type.getId() %>" value="<%=oldNum==0?"":oldNum %>"/>&nbsp;次<%=type.getReasonType() %><br/><br/>
<%}}%>
<input type="hidden" name="pageType" value="hiCyoung">
</div>
<p class="submit"><input type="submit" value="提交"></p>
</div>
</form>
<%}else{
	    List<ParamReasonTypeGS> gss = new ArrayList<ParamReasonTypeGS>();
    	for(ParamReasonType type:types){
		        if(type.getId()!=3&&type.getId()!=1){
		            int num = ParamUtil.getInt(request,""+type.getId(),0);
		            int reasonTypeId = type.getId();
		            ParamReasonTypeGS oldGS=ParamReasonTypeGSControl.getGSByTypeAndStuyear(type.getId(),stuyear);
		            ParamReasonTypeGS gs = null;
		            if(num>0){
		        	     if(oldGS==null){
		        	          gs = new ParamReasonTypeGS(num,reasonTypeId,stuyear);
				            }else{
				        	          gs = oldGS;
				        	          gs.setNum(num);
				            }
		        	     gss.add(gs);
		        	}
		            }
		  }
		   if(ParamReasonTypeGSControl.isInserted(stuyear)){
				       if(ParamReasonTypeGSControl.updateGSByStuyear(gss)){
				       %>
				       <script>
		               $.dialog({
						    title: '设置缺勤计算公式',
						    content: '本学期的公式修改成功',
						    icon: 'succeed',
						    ok: function(){
		            	   		window.top.location.href="stuyear_start.jsp";
						    }
						});
               </script>
				       <%
					   }else{
					       %>
					       <script>
			               $.dialog({
							    title: '设置缺勤计算公式',
							    content: '抱歉，本学期的公式修改失败，请检查您的输入是否有误',
							    icon: 'error',
							    ok: function(){
			            	   		window.top.location.href="stuyear_start.jsp";
							    }
							});
	               </script>
					       <%
					   }
		   }else{
		       gss.add(new ParamReasonTypeGS(1,3,stuyear));
		       if(ParamReasonTypeGSControl.insertGS(gss)){
			   %>
			     <script>
		               $.dialog({
						    title: '设置缺勤计算公式',
						    content: '本学期的公式添加成功',
						    icon: 'succeed',
						    ok: function(){
		            	   		window.top.location.href="stuyear_start.jsp";
						    }
						});
               </script>
			       <%
		       }else{
			   %>
			       <script>
			               $.dialog({
							    title: '设置缺勤计算公式',
							    content: '抱歉，本学期的公式添加失败，请检查您的输入是否有误',
							    icon: 'error',
							    ok: function(){
			            	   		window.top.location.href="stuyear_start.jsp";
							    }
							});
	               </script>
			       <%
		       }
		   }
		     
		    } %>
</body>
</html>